import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
	state:{
		hasLogin: false,// dev
		forcedLogin: true,
		loginProvider: "",
		token:"",
		openid: null,
		usertype:""
	},
	mutations:{
		login(state,token){
			state.hasLogin = true;
			state.loginProvider = '';
			state.token = token;
			// state.usertype = usertype;
			uni.setStorageSync('token', token);
			uni.setStorageSync('trueLogin', true);
			// uni.setStorageSync('usertype', usertype);
		},
		logout(state){
			state.hasLogin = false;
			state.loginProvider = '';
			state.usertype = '';
			state.openid = null,
			uni.setStorageSync('token', '');
			uni.setStorageSync('trueLogin', false);
			// uni.setStorageSync('usertype', '');
		}	
	},
	setToken(state,token){
		state.token = token
	},
	setOpenid(state, openid) {
		state.openid = openid
	},
	setUsertype(state, usertype) {
		state.usertype = usertype;
		uni.setStorageSync('usertype', usertype);
	},
})

export default store
